﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using VideoClub.EN.classes;

namespace VideoClub.DS.classes.vw
{
   public class Sp_Vw_Handler
    {
        public bool selectMoviesByCategory(CategoriaPelicula categoriapelicula, ref DataSet respuesta, ref string log)
        {
            try
            {
               
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                { 
                    conec.Open();
                    SqlCommand cmd = new SqlCommand("Sp_select_moviesbycategory", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidcategoria", SqlDbType.Int).Value = categoriapelicula.Idcategoriapelicula;                  
                    SqlDataAdapter adpt = new SqlDataAdapter(cmd);           
                    adpt.Fill(respuesta);
                    log += "workiinggg --> "+respuesta.Tables[0].Rows.Count;
                    return true;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }
        public bool selectDetailedMovie(Pelicula pelicula, ref DataSet respuesta, ref string log)
        {
            try
            {

                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    conec.Open();
                    SqlCommand cmd = new SqlCommand("Sp_select_moviedetailed", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidpelicula", SqlDbType.Int).Value = pelicula.Idpelicula;
                    SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                    adpt.Fill(respuesta);
                    log += "workiinggg --> " + respuesta.Tables[0].Rows.Count;
                    return true;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

    }
}
